#include "stdafx.h"
#include "AveragingPerformanceData.h"

void CAveragingPerformanceDataStore::AddPerformanceData(const wchar_t* szwDescription, double elapsedTime)
{ 
	auto it = this->keyVal.find(szwDescription);
	if (it != this->keyVal.end())
	{
		++std::get<0>(it->second);
		std::get<1>(it->second) += elapsedTime;
	}  
	else
	{
		this->keyVal.insert(std::make_pair(std::wstring(szwDescription), std::make_tuple(1, elapsedTime)));
	}
}

void CAveragingPerformanceDataStore::EnumeratePerformanceData(std::function<bool(const std::wstring&, double sum, int count)> func)
{
	for (const auto &pair : this->keyVal)
	{
		int count = std::get<0>(pair.second);
		double sum = std::get<1>(pair.second);
		bool b = func(pair.first, sum, count);
		if (b == false)
		{
			break;
		}
	}
}

bool CAveragingPerformanceDataStore::isEmpty() const
{
	return this->keyVal.empty();
}